package controller.sevlet.page;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class setShopCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	@SuppressWarnings("unchecked")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Map<String,String> ids = (Map<String,String>)request.getParameterMap();
		List<String> id0 = new ArrayList<String>();
		for(String i : ids.keySet()){
			String[] tmp = i.split("/");
			id0.add(tmp[1]);
		}
		HttpSession session = request.getSession(false);
		HashMap<String, Integer> shopCart = (HashMap<String, Integer>) session.getAttribute("shopCart");
		for(String i : id0){
			int qtde = Integer.parseInt(request.getParameter("quantity/"+i));
			shopCart.put(i,qtde);
		}
		response.getWriter().println("1");	
	}

}
